package jmetal.problems.adaboost;

import org.opencv.core.*;


public class Feature1 extends Feature{

	public Feature1()
	{
		setType(1);
		setMinHeight(1);
		setMinWidth(2);
	}
	
	
	@Override
	public double calculateValue(double[][] image, int x, int y, int width, int height) {
		// double result = 0;
		double result = 0;
		double A1, B1, C1, D1, A2, B2, C2, D2;
		if(y==0)
		{
			A1 = C1 = A2 = C2 = 0;
			if(x == 0)
			{
				B1 = 0;
			}
			else
			{
				B1 = image[x-1][y+height -1];
			}
		}
		else if(x == 0)
		{
			A1 = B1 = 0;
			C1 = image[(x + (width / 2)) - 1][y - 1];
			A2 = C1;
			C2 = image[(x + width) - 1][y - 1]; 
		}
		else
		{
			B1 = image[x - 1][(y + height) - 1];
			A1 = image[x - 1][y - 1];
			C1 = image[(x + (width / 2)) - 1][y - 1];
			A2 = C1;
			C2 = image[(x + width) - 1][y - 1];
		}
		D1 = image[x - 1 + (width / 2)][y - 1 + height];
		D2 = image[x - 1 + width][y - 1 + height];
		B2 = D1;
		double branco = A1 + D1 - (B1 + C1);
		double preto = A2 + D2 - (B2 + C2);
		result = preto - branco;
		setValue(result);
		return result;
	}

	
	
	
}
